<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        // await 必须放在async函数中。但是async可以没有await，不过一般都写在一起
        // 创建promise对象
        const p = new Promise((resolve, reject) => {
            // resolve("成功的值");
            reject("失败了！");
        })

        // await要放在async函数中
        async function main() {
            try {
                let result = await p;
                console.log(result);
            } catch (error) {
                // 对失败的结果进行处理
                console.log(error);
            }
        }
        // 调用函数main
        main();
    </script>
</body>

</html>